﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.SqlClient;
using System.Data;
using Aliyeye.Car.Net.Utility;

namespace Aliyeye.Car.Net.Dal
{
    public class Car
    {
        public Car()
        { }
        public int Add(Model.Car model)
        {
            try
            {
                SqlParameter[] parameters = {
					new SqlParameter("@Id", SqlDbType.Int,4),
					new SqlParameter("@Code", SqlDbType.NVarChar,50),
					new SqlParameter("@Cartype", SqlDbType.NVarChar,50),
					new SqlParameter("@Color", SqlDbType.NVarChar,50),
					new SqlParameter("@FactorCode", SqlDbType.NVarChar,50),
					new SqlParameter("@MotorCode", SqlDbType.NVarChar,50),
					new SqlParameter("@dipanCode", SqlDbType.NVarChar,50),
					new SqlParameter("@StarMax", SqlDbType.BigInt),
					new SqlParameter("@Max", SqlDbType.BigInt),
					new SqlParameter("@BuyTime", SqlDbType.DateTime),
					new SqlParameter("@CareTime", SqlDbType.DateTime),
					new SqlParameter("@EndCare", SqlDbType.DateTime),
					new SqlParameter("@Drive", SqlDbType.Bit,1),
					new SqlParameter("@InsureTime", SqlDbType.DateTime),
					new SqlParameter("@InsureEnd", SqlDbType.DateTime),
					new SqlParameter("@RoadTime", SqlDbType.DateTime),
					new SqlParameter("@RoadEnd", SqlDbType.DateTime),
					new SqlParameter("@Path", SqlDbType.NVarChar,50),
					new SqlParameter("@State", SqlDbType.Bit,1),
					new SqlParameter("@Seat", SqlDbType.NVarChar,50),
					new SqlParameter("@BuyPrice", SqlDbType.Decimal),
					new SqlParameter("@Tax", SqlDbType.Decimal,9),
					new SqlParameter("@Shangpaishui", SqlDbType.Decimal),
					new SqlParameter("@Decorate", SqlDbType.NVarChar,100),
					new SqlParameter("@Owners", SqlDbType.NVarChar,50),
					new SqlParameter("@OwnerTel", SqlDbType.NVarChar,50),
					new SqlParameter("@StarOPen", SqlDbType.DateTime),
					new SqlParameter("@EndOpen", SqlDbType.DateTime),
					new SqlParameter("@StarPasTime", SqlDbType.DateTime),
					new SqlParameter("@EndPass", SqlDbType.DateTime),
					new SqlParameter("@StarCard", SqlDbType.DateTime),
					new SqlParameter("@EndCard", SqlDbType.DateTime),
					new SqlParameter("@Staryunguan", SqlDbType.DateTime),
					new SqlParameter("@Endyunguan", SqlDbType.DateTime),
					new SqlParameter("@Starbridge", SqlDbType.DateTime),
					new SqlParameter("@Endbridge", SqlDbType.DateTime),
					new SqlParameter("@StarCheshui", SqlDbType.DateTime),
					new SqlParameter("@EndChenshui", SqlDbType.DateTime),
					new SqlParameter("@TimeoutPrie", SqlDbType.Decimal,9),
					new SqlParameter("@OvertimePrie", SqlDbType.Decimal,9),
					new SqlParameter("@DepID", SqlDbType.Int,4),
					new SqlParameter("@UserId", SqlDbType.Int,4),
					new SqlParameter("@ShangPaiFei", SqlDbType.Decimal,9),
					new SqlParameter("@SendMile", SqlDbType.Int,4),
					new SqlParameter("@NextMile", SqlDbType.BigInt),
					new SqlParameter("@Marks", SqlDbType.NVarChar,800),
					new SqlParameter("@Brand", SqlDbType.NVarChar,50),
					new SqlParameter("@WarrTime", SqlDbType.DateTime),
					new SqlParameter("@CarTime", SqlDbType.DateTime),
					new SqlParameter("@DayRent", SqlDbType.Decimal),
					new SqlParameter("@CarKind", SqlDbType.NVarChar,50),
					new SqlParameter("@FactoryOutDate", SqlDbType.DateTime),
					new SqlParameter("@IsSelf", SqlDbType.Bit,1),
					new SqlParameter("@IsActive", SqlDbType.Bit,1),
					new SqlParameter("@DayDeposit", SqlDbType.Decimal),
					new SqlParameter("@DayLimitKM", SqlDbType.BigInt),
					new SqlParameter("@MonthRent", SqlDbType.Decimal),
					new SqlParameter("@MonthDeposit", SqlDbType.Decimal),
					new SqlParameter("@MonthLimitKM", SqlDbType.BigInt),
					new SqlParameter("@YearRent", SqlDbType.Decimal),
					new SqlParameter("@YearDeposit", SqlDbType.Decimal),
					new SqlParameter("@YearLimitKM", SqlDbType.BigInt),
					new SqlParameter("@AirportShuttleOneWay", SqlDbType.Decimal),
					new SqlParameter("@AirportShuttleTwoWay", SqlDbType.Decimal),
					new SqlParameter("@Chartered3Rent", SqlDbType.Decimal),
					new SqlParameter("@Chartered8Rent", SqlDbType.Decimal),
					new SqlParameter("@OutdatedFee3", SqlDbType.Decimal),
					new SqlParameter("@OutdatedFee8", SqlDbType.Decimal),
					new SqlParameter("@LongJourneys1", SqlDbType.Decimal),
					new SqlParameter("@LongJourneys2", SqlDbType.Decimal),
					new SqlParameter("@LongJourneys3", SqlDbType.Decimal),
					new SqlParameter("@ExhaustVolume", SqlDbType.Float),
					new SqlParameter("@CarImage", SqlDbType.Image),
					new SqlParameter("@CommissionRatio", SqlDbType.Int,4)
                                            };
                parameters[0].Direction = ParameterDirection.Output;
                parameters[1].Value = model.Code;
                parameters[2].Value = model.Cartype;
                parameters[3].Value = model.Color;
                parameters[4].Value = model.FactorCode;
                parameters[5].Value = model.MotorCode;
                parameters[6].Value = model.dipanCode;
                parameters[7].Value = model.StarMax;
                parameters[8].Value = model.Max;
                parameters[9].Value = model.BuyTime;
                parameters[10].Value = model.CareTime;
                parameters[11].Value = model.EndCare;
                parameters[12].Value = model.Drive;
                parameters[13].Value = model.InsureTime;
                parameters[14].Value = model.InsureEnd;
                parameters[15].Value = model.RoadTime;
                parameters[16].Value = model.RoadEnd;
                parameters[17].Value = model.Path;
                parameters[18].Value = model.State;
                parameters[19].Value = model.Seat;
                parameters[20].Value = model.BuyPrice;
                parameters[21].Value = model.Tax;
                parameters[22].Value = model.Shangpaishui;
                parameters[23].Value = model.Decorate;
                parameters[24].Value = model.Owners;
                parameters[25].Value = model.OwnerTel;
                parameters[26].Value = model.StarOPen;
                parameters[27].Value = model.EndOpen;
                parameters[28].Value = model.StarPasTime;
                parameters[29].Value = model.EndPass;
                parameters[30].Value = model.StarCard;
                parameters[31].Value = model.EndCard;
                parameters[32].Value = model.Staryunguan;
                parameters[33].Value = model.Endyunguan;
                parameters[34].Value = model.Starbridge;
                parameters[35].Value = model.Endbridge;
                parameters[36].Value = model.StarCheshui;
                parameters[37].Value = model.EndChenshui;
                parameters[38].Value = model.TimeoutPrie;
                parameters[39].Value = model.OvertimePrie;
                parameters[40].Value = model.DepID;
                parameters[41].Value = model.UserId;
                parameters[42].Value = model.ShangPaiFei;
                parameters[43].Value = model.SendMile;
                parameters[44].Value = model.NextMile;
                parameters[45].Value = model.Marks;
                parameters[46].Value = model.Brand;
                parameters[47].Value = model.WarrTime;
                parameters[48].Value = model.CarTime;
                parameters[49].Value = model.DayRent;
                parameters[50].Value = model.CarKind;
                parameters[51].Value = model.FactoryOutDate;
                parameters[52].Value = model.IsSelf;
                parameters[53].Value = model.IsActive;

                parameters[54].Value = model.DayDeposit;
                parameters[55].Value = model.DayLimitKM;
                parameters[56].Value = model.MonthRent;
                parameters[57].Value = model.MonthDeposit;
                parameters[58].Value = model.MonthLimitKM;
                parameters[59].Value = model.YearRent;
                parameters[60].Value = model.YearDeposit;
                parameters[61].Value = model.YearLimitKM;
                parameters[62].Value = model.AirportShuttleOneWay;
                parameters[63].Value = model.AirportShuttleTwoWay;
                parameters[64].Value = model.Chartered3Rent;
                parameters[65].Value = model.Chartered8Rent;
                parameters[66].Value = model.OutdatedFee3;
                parameters[67].Value = model.OutdatedFee8;
                parameters[68].Value = model.LongJourneys1;
                parameters[69].Value = model.LongJourneys2;
                parameters[70].Value = model.LongJourneys3;
                parameters[71].Value = model.ExhaustVolume;
                parameters[72].Value = model.CarImage;
                parameters[73].Value = model.CommissionRatio;

                int roleId = SqlHelper.ExecuteNonQuery(CommandType.StoredProcedure, "ArticleCar_ADD", parameters);
                if (roleId > 0)
                {
                    return roleId;
                }
                else
                {
                    return 0;
                }
            }
            catch (Exception )
            {
                return 0;
            }
        }
        public bool Update(Model.Car model)
        {
            SqlParameter[] parameters = {
					new SqlParameter("@Id", SqlDbType.Int,4),
					new SqlParameter("@Code", SqlDbType.NVarChar,50),
					new SqlParameter("@Cartype", SqlDbType.NVarChar,50),
					new SqlParameter("@Color", SqlDbType.NVarChar,50),
					new SqlParameter("@FactorCode", SqlDbType.NVarChar,50),
					new SqlParameter("@MotorCode", SqlDbType.NVarChar,50),
					new SqlParameter("@dipanCode", SqlDbType.NVarChar,50),
					new SqlParameter("@StarMax", SqlDbType.BigInt),
					new SqlParameter("@Max", SqlDbType.BigInt),
					new SqlParameter("@BuyTime", SqlDbType.DateTime),
					new SqlParameter("@CareTime", SqlDbType.DateTime),
					new SqlParameter("@EndCare", SqlDbType.DateTime),
					new SqlParameter("@Drive", SqlDbType.Bit,1),
					new SqlParameter("@InsureTime", SqlDbType.DateTime),
					new SqlParameter("@InsureEnd", SqlDbType.DateTime),
					new SqlParameter("@RoadTime", SqlDbType.DateTime),
					new SqlParameter("@RoadEnd", SqlDbType.DateTime),
					new SqlParameter("@Path", SqlDbType.NVarChar,50),
					new SqlParameter("@State", SqlDbType.Bit,1),
					new SqlParameter("@Seat", SqlDbType.NVarChar,50),
					new SqlParameter("@BuyPrice", SqlDbType.Decimal,9),
					new SqlParameter("@Tax", SqlDbType.Decimal,9),
					new SqlParameter("@Shangpaishui", SqlDbType.Decimal,9),
					new SqlParameter("@Decorate", SqlDbType.NVarChar,100),
					new SqlParameter("@Owners", SqlDbType.NVarChar,50),
					new SqlParameter("@OwnerTel", SqlDbType.NVarChar,50),
					new SqlParameter("@StarOPen", SqlDbType.DateTime),
					new SqlParameter("@EndOpen", SqlDbType.DateTime),
					new SqlParameter("@StarPasTime", SqlDbType.DateTime),
					new SqlParameter("@EndPass", SqlDbType.DateTime),
					new SqlParameter("@StarCard", SqlDbType.DateTime),
					new SqlParameter("@EndCard", SqlDbType.DateTime),
					new SqlParameter("@Staryunguan", SqlDbType.DateTime),
					new SqlParameter("@Endyunguan", SqlDbType.DateTime),
					new SqlParameter("@Starbridge", SqlDbType.DateTime),
					new SqlParameter("@Endbridge", SqlDbType.DateTime),
					new SqlParameter("@StarCheshui", SqlDbType.DateTime),
					new SqlParameter("@EndChenshui", SqlDbType.DateTime),
					new SqlParameter("@TimeoutPrie", SqlDbType.Decimal,9),
					new SqlParameter("@OvertimePrie", SqlDbType.Decimal,9),
					new SqlParameter("@DepID", SqlDbType.Int,4),
					new SqlParameter("@UserId", SqlDbType.Int,4),
					new SqlParameter("@ShangPaiFei", SqlDbType.Decimal,9),
					new SqlParameter("@SendMile", SqlDbType.Int,4),
					new SqlParameter("@NextMile", SqlDbType.BigInt),
					new SqlParameter("@Marks", SqlDbType.NVarChar,800),
					new SqlParameter("@Brand", SqlDbType.NVarChar,50),
					new SqlParameter("@WarrTime", SqlDbType.DateTime),
					new SqlParameter("@CarTime", SqlDbType.DateTime),
					new SqlParameter("@DayRent", SqlDbType.Decimal),
					new SqlParameter("@CarKind", SqlDbType.NVarChar,50),
					new SqlParameter("@FactoryOutDate", SqlDbType.DateTime),
					new SqlParameter("@IsSelf", SqlDbType.Bit,1),
					new SqlParameter("@IsActive", SqlDbType.Bit,1),
					new SqlParameter("@DayDeposit", SqlDbType.Decimal),
					new SqlParameter("@DayLimitKM", SqlDbType.BigInt),
					new SqlParameter("@MonthRent", SqlDbType.Decimal),
					new SqlParameter("@MonthDeposit", SqlDbType.Decimal),
					new SqlParameter("@MonthLimitKM", SqlDbType.BigInt),
					new SqlParameter("@YearRent", SqlDbType.Decimal),
					new SqlParameter("@YearDeposit", SqlDbType.Decimal),
					new SqlParameter("@YearLimitKM", SqlDbType.BigInt),
					new SqlParameter("@AirportShuttleOneWay", SqlDbType.Decimal),
					new SqlParameter("@AirportShuttleTwoWay", SqlDbType.Decimal),
					new SqlParameter("@Chartered3Rent", SqlDbType.Decimal),
					new SqlParameter("@Chartered8Rent", SqlDbType.Decimal),
					new SqlParameter("@OutdatedFee3", SqlDbType.Decimal),
					new SqlParameter("@OutdatedFee8", SqlDbType.Decimal),
					new SqlParameter("@LongJourneys1", SqlDbType.Decimal),
					new SqlParameter("@LongJourneys2", SqlDbType.Decimal),
					new SqlParameter("@LongJourneys3", SqlDbType.Decimal),
					new SqlParameter("@ExhaustVolume", SqlDbType.Float),
					new SqlParameter("@CarImage", SqlDbType.Image),
					new SqlParameter("@CommissionRatio", SqlDbType.Int,4)
                                        };
            parameters[0].Value = model.Id;
            parameters[1].Value = model.Code;
            parameters[2].Value = model.Cartype;
            parameters[3].Value = model.Color;
            parameters[4].Value = model.FactorCode;
            parameters[5].Value = model.MotorCode;
            parameters[6].Value = model.dipanCode;
            parameters[7].Value = model.StarMax;
            parameters[8].Value = model.Max;
            parameters[9].Value = model.BuyTime;
            parameters[10].Value = model.CareTime;
            parameters[11].Value = model.EndCare;
            parameters[12].Value = model.Drive;
            parameters[13].Value = model.InsureTime;
            parameters[14].Value = model.InsureEnd;
            parameters[15].Value = model.RoadTime;
            parameters[16].Value = model.RoadEnd;
            parameters[17].Value = model.Path;
            parameters[18].Value = model.State;
            parameters[19].Value = model.Seat;
            parameters[20].Value = model.BuyPrice;
            parameters[21].Value = model.Tax;
            parameters[22].Value = model.Shangpaishui;
            parameters[23].Value = model.Decorate;
            parameters[24].Value = model.Owners;
            parameters[25].Value = model.OwnerTel;
            parameters[26].Value = model.StarOPen;
            parameters[27].Value = model.EndOpen;
            parameters[28].Value = model.StarPasTime;
            parameters[29].Value = model.EndPass;
            parameters[30].Value = model.StarCard;
            parameters[31].Value = model.EndCard;
            parameters[32].Value = model.Staryunguan;
            parameters[33].Value = model.Endyunguan;
            parameters[34].Value = model.Starbridge;
            parameters[35].Value = model.Endbridge;
            parameters[36].Value = model.StarCheshui;
            parameters[37].Value = model.EndChenshui;
            parameters[38].Value = model.TimeoutPrie;
            parameters[39].Value = model.OvertimePrie;
            parameters[40].Value = model.DepID;
            parameters[41].Value = model.UserId;
            parameters[42].Value = model.ShangPaiFei;
            parameters[43].Value = model.SendMile;
            parameters[44].Value = model.NextMile;
            parameters[45].Value = model.Marks;
            parameters[46].Value = model.Brand;
            parameters[47].Value = model.WarrTime;
            parameters[48].Value = model.CarTime;
            parameters[49].Value = model.DayRent;
            parameters[50].Value = model.CarKind;
            parameters[51].Value = model.FactoryOutDate;
            parameters[52].Value = model.IsSelf;
            parameters[53].Value = model.IsActive;

            parameters[54].Value = model.DayDeposit;
            parameters[55].Value = model.DayLimitKM;
            parameters[56].Value = model.MonthRent;
            parameters[57].Value = model.MonthDeposit;
            parameters[58].Value = model.MonthLimitKM;
            parameters[59].Value = model.YearRent;
            parameters[60].Value = model.YearDeposit;
            parameters[61].Value = model.YearLimitKM;
            parameters[62].Value = model.AirportShuttleOneWay;
            parameters[63].Value = model.AirportShuttleTwoWay;
            parameters[64].Value = model.Chartered3Rent;
            parameters[65].Value = model.Chartered8Rent;
            parameters[66].Value = model.OutdatedFee3;
            parameters[67].Value = model.OutdatedFee8;
            parameters[68].Value = model.LongJourneys1;
            parameters[69].Value = model.LongJourneys2;
            parameters[70].Value = model.LongJourneys3;
            parameters[71].Value = model.ExhaustVolume;
            parameters[72].Value = model.CarImage;
            parameters[73].Value = model.CommissionRatio;

            int intResult = SqlHelper.ExecuteNonQuery(CommandType.StoredProcedure, "ArticleCar_Update", parameters);
            if (intResult > 0)
                return true;
            else
                return false;
        }
        public bool Delete(int Id)
        {
            SqlParameter[] parameters = {
					new SqlParameter("@Id", SqlDbType.Int,4)};
            parameters[0].Value = Id;
            int intResult = SqlHelper.ExecuteNonQuery(CommandType.StoredProcedure, "ArticleCar_Delete", parameters);
            if (intResult > 0)
                return true;
            else
                return false;
        }
        public Model.Car GetModel(int Id)
        {
            SqlParameter[] parameters = {
					new SqlParameter("@Id", SqlDbType.Int,4)};
            parameters[0].Value = Id;

            Model.Car model = new Model.Car();
            DataSet ds = SqlHelper.GetDataFormDataSet(CommandType.StoredProcedure, "ArticleCar_GetModel", parameters);
            if (ds.Tables[0].Rows.Count > 0)
            {
                if (ds.Tables[0].Rows[0]["Id"].ToString() != "")
                {
                    model.Id = int.Parse(ds.Tables[0].Rows[0]["Id"].ToString());
                }
                model.Code = ds.Tables[0].Rows[0]["Code"].ToString();
                model.Cartype = ds.Tables[0].Rows[0]["Cartype"].ToString();
                model.Color = ds.Tables[0].Rows[0]["Color"].ToString();
                model.FactorCode = ds.Tables[0].Rows[0]["FactorCode"].ToString();
                model.MotorCode = ds.Tables[0].Rows[0]["MotorCode"].ToString();
                model.dipanCode = ds.Tables[0].Rows[0]["dipanCode"].ToString();
                if (ds.Tables[0].Rows[0]["StarMax"].ToString() != "")
                {
                    model.StarMax = int.Parse(ds.Tables[0].Rows[0]["StarMax"].ToString());
                }
                if (ds.Tables[0].Rows[0]["Max"].ToString() != "")
                {
                    model.Max = int.Parse(ds.Tables[0].Rows[0]["Max"].ToString());
                }
                if (ds.Tables[0].Rows[0]["BuyTime"].ToString() != "")
                {
                    model.BuyTime = DateTime.Parse(ds.Tables[0].Rows[0]["BuyTime"].ToString());
                }
                if (ds.Tables[0].Rows[0]["CareTime"].ToString() != "")
                {
                    model.CareTime = DateTime.Parse(ds.Tables[0].Rows[0]["CareTime"].ToString());
                }
                if (ds.Tables[0].Rows[0]["EndCare"].ToString() != "")
                {
                    model.EndCare = DateTime.Parse(ds.Tables[0].Rows[0]["EndCare"].ToString());
                }
                if (ds.Tables[0].Rows[0]["Drive"].ToString() != "")
                {
                    if ((ds.Tables[0].Rows[0]["Drive"].ToString() == "1") || (ds.Tables[0].Rows[0]["Drive"].ToString().ToLower() == "true"))
                    {
                        model.Drive = true;
                    }
                    else
                    {
                        model.Drive = false;
                    }
                }
                if (ds.Tables[0].Rows[0]["InsureTime"].ToString() != "")
                {
                    model.InsureTime = DateTime.Parse(ds.Tables[0].Rows[0]["InsureTime"].ToString());
                }
                if (ds.Tables[0].Rows[0]["InsureEnd"].ToString() != "")
                {
                    model.InsureEnd = DateTime.Parse(ds.Tables[0].Rows[0]["InsureEnd"].ToString());
                }
                if (ds.Tables[0].Rows[0]["RoadTime"].ToString() != "")
                {
                    model.RoadTime = DateTime.Parse(ds.Tables[0].Rows[0]["RoadTime"].ToString());
                }
                if (ds.Tables[0].Rows[0]["RoadEnd"].ToString() != "")
                {
                    model.RoadEnd = DateTime.Parse(ds.Tables[0].Rows[0]["RoadEnd"].ToString());
                }
                model.Path = ds.Tables[0].Rows[0]["Path"].ToString();
                if (ds.Tables[0].Rows[0]["State"].ToString() != "")
                {
                    if ((ds.Tables[0].Rows[0]["State"].ToString() == "1") || (ds.Tables[0].Rows[0]["State"].ToString().ToLower() == "true"))
                    {
                        model.State = true;
                    }
                    else
                    {
                        model.State = false;
                    }
                }
                model.Seat = ds.Tables[0].Rows[0]["Seat"].ToString();
                if (ds.Tables[0].Rows[0]["BuyPrice"].ToString() != "")
                {
                    model.BuyPrice = decimal.Parse(ds.Tables[0].Rows[0]["BuyPrice"].ToString());
                }
                if (ds.Tables[0].Rows[0]["Tax"].ToString() != "")
                {
                    model.Tax = decimal.Parse(ds.Tables[0].Rows[0]["Tax"].ToString());
                }
                if (ds.Tables[0].Rows[0]["Shangpaishui"].ToString() != "")
                {
                    model.Shangpaishui = decimal.Parse(ds.Tables[0].Rows[0]["Shangpaishui"].ToString());
                }
                model.Decorate = ds.Tables[0].Rows[0]["Decorate"].ToString();
                model.Owners = ds.Tables[0].Rows[0]["Owners"].ToString();
                model.OwnerTel = ds.Tables[0].Rows[0]["OwnerTel"].ToString();
                if (ds.Tables[0].Rows[0]["StarOPen"].ToString() != "")
                {
                    model.StarOPen = DateTime.Parse(ds.Tables[0].Rows[0]["StarOPen"].ToString());
                }
                if (ds.Tables[0].Rows[0]["EndOpen"].ToString() != "")
                {
                    model.EndOpen = DateTime.Parse(ds.Tables[0].Rows[0]["EndOpen"].ToString());
                }
                if (ds.Tables[0].Rows[0]["StarPasTime"].ToString() != "")
                {
                    model.StarPasTime = DateTime.Parse(ds.Tables[0].Rows[0]["StarPasTime"].ToString());
                }
                if (ds.Tables[0].Rows[0]["EndPass"].ToString() != "")
                {
                    model.EndPass = DateTime.Parse(ds.Tables[0].Rows[0]["EndPass"].ToString());
                }
                if (ds.Tables[0].Rows[0]["StarCard"].ToString() != "")
                {
                    model.StarCard = DateTime.Parse(ds.Tables[0].Rows[0]["StarCard"].ToString());
                }
                if (ds.Tables[0].Rows[0]["EndCard"].ToString() != "")
                {
                    model.EndCard = DateTime.Parse(ds.Tables[0].Rows[0]["EndCard"].ToString());
                }
                if (ds.Tables[0].Rows[0]["Staryunguan"].ToString() != "")
                {
                    model.Staryunguan = DateTime.Parse(ds.Tables[0].Rows[0]["Staryunguan"].ToString());
                }
                if (ds.Tables[0].Rows[0]["Endyunguan"].ToString() != "")
                {
                    model.Endyunguan = DateTime.Parse(ds.Tables[0].Rows[0]["Endyunguan"].ToString());
                }
                if (ds.Tables[0].Rows[0]["Starbridge"].ToString() != "")
                {
                    model.Starbridge = DateTime.Parse(ds.Tables[0].Rows[0]["Starbridge"].ToString());
                }
                if (ds.Tables[0].Rows[0]["Endbridge"].ToString() != "")
                {
                    model.Endbridge = DateTime.Parse(ds.Tables[0].Rows[0]["Endbridge"].ToString());
                }
                if (ds.Tables[0].Rows[0]["StarCheshui"].ToString() != "")
                {
                    model.StarCheshui = DateTime.Parse(ds.Tables[0].Rows[0]["StarCheshui"].ToString());
                }
                if (ds.Tables[0].Rows[0]["EndChenshui"].ToString() != "")
                {
                    model.EndChenshui = DateTime.Parse(ds.Tables[0].Rows[0]["EndChenshui"].ToString());
                }
                if (ds.Tables[0].Rows[0]["TimeoutPrie"].ToString() != "")
                {
                    model.TimeoutPrie = decimal.Parse(ds.Tables[0].Rows[0]["TimeoutPrie"].ToString());
                }
                if (ds.Tables[0].Rows[0]["OvertimePrie"].ToString() != "")
                {
                    model.OvertimePrie = decimal.Parse(ds.Tables[0].Rows[0]["OvertimePrie"].ToString());
                }
                if (ds.Tables[0].Rows[0]["DepID"].ToString() != "")
                {
                    model.DepID = int.Parse(ds.Tables[0].Rows[0]["DepID"].ToString());
                }
                if (ds.Tables[0].Rows[0]["UserId"].ToString() != "")
                {
                    model.UserId = int.Parse(ds.Tables[0].Rows[0]["UserId"].ToString());
                }
                if (ds.Tables[0].Rows[0]["ShangPaiFei"].ToString() != "")
                {
                    model.ShangPaiFei = decimal.Parse(ds.Tables[0].Rows[0]["ShangPaiFei"].ToString());
                }
                if (ds.Tables[0].Rows[0]["SendMile"].ToString() != "")
                {
                    model.SendMile = int.Parse(ds.Tables[0].Rows[0]["SendMile"].ToString());
                }
                if (ds.Tables[0].Rows[0]["NextMile"].ToString() != "")
                {
                    model.NextMile = int.Parse(ds.Tables[0].Rows[0]["NextMile"].ToString());
                }
                model.Marks = ds.Tables[0].Rows[0]["Marks"].ToString();
                model.Brand = ds.Tables[0].Rows[0]["Brand"].ToString();
                if (ds.Tables[0].Rows[0]["WarrTime"].ToString() != "")
                {
                    model.WarrTime = DateTime.Parse(ds.Tables[0].Rows[0]["WarrTime"].ToString());
                }
                if (ds.Tables[0].Rows[0]["CarTime"].ToString() != "")
                {
                    model.CarTime = DateTime.Parse(ds.Tables[0].Rows[0]["CarTime"].ToString());
                }
                if (ds.Tables[0].Rows[0]["DayRent"].ToString() != "")
                {
                    model.DayRent = decimal.Parse(ds.Tables[0].Rows[0]["DayRent"].ToString());
                }
                if (ds.Tables[0].Rows[0]["FactoryOutDate"] == DBNull.Value)
                {
                    model.FactoryOutDate = DateTime.Now;
                }
                else if (ds.Tables[0].Rows[0]["FactoryOutDate"].ToString() != "")
                {
                    model.FactoryOutDate = DateTime.Parse(ds.Tables[0].Rows[0]["FactoryOutDate"].ToString());
                }
                if (ds.Tables[0].Rows[0]["IsSelf"].ToString() != "")
                {
                    if ((ds.Tables[0].Rows[0]["IsSelf"].ToString() == "1") || (ds.Tables[0].Rows[0]["IsSelf"].ToString().ToLower() == "true"))
                    {
                        model.IsSelf = true;
                    }
                    else
                    {
                        model.IsSelf = false;
                    }
                }
                if (ds.Tables[0].Rows[0]["IsActive"].ToString() != "")
                {
                    if ((ds.Tables[0].Rows[0]["IsActive"].ToString() == "1") || (ds.Tables[0].Rows[0]["IsActive"].ToString().ToLower() == "true"))
                    {
                        model.IsActive = true;
                    }
                    else
                    {
                        model.IsActive = false;
                    }
                }
                model.CarKind = ds.Tables[0].Rows[0]["CarKind"].ToString();
                model.DriverName = ds.Tables[0].Rows[0]["DriverName"].ToString();
                model.DriverTel = ds.Tables[0].Rows[0]["DriverTel"].ToString();

                if (ds.Tables[0].Rows[0]["DayDeposit"].ToString() != "")
                {
                    model.DayDeposit = decimal.Parse(ds.Tables[0].Rows[0]["DayDeposit"].ToString());
                }
                if (ds.Tables[0].Rows[0]["DayLimitKM"].ToString() != "")
                {
                    model.DayLimitKM = Convert.ToInt64(ds.Tables[0].Rows[0]["DayLimitKM"].ToString());
                }
                if (ds.Tables[0].Rows[0]["MonthRent"].ToString() != "")
                {
                    model.MonthRent = decimal.Parse(ds.Tables[0].Rows[0]["MonthRent"].ToString());
                }
                if (ds.Tables[0].Rows[0]["MonthDeposit"].ToString() != "")
                {
                    model.MonthDeposit = decimal.Parse(ds.Tables[0].Rows[0]["MonthDeposit"].ToString());
                }
                if (ds.Tables[0].Rows[0]["MonthLimitKM"].ToString() != "")
                {
                    model.MonthLimitKM =Convert.ToInt64(ds.Tables[0].Rows[0]["MonthLimitKM"].ToString());
                }
                if (ds.Tables[0].Rows[0]["YearRent"].ToString() != "")
                {
                    model.YearRent = decimal.Parse(ds.Tables[0].Rows[0]["YearRent"].ToString());
                }
                if (ds.Tables[0].Rows[0]["YearDeposit"].ToString() != "")
                {
                    model.YearDeposit = decimal.Parse(ds.Tables[0].Rows[0]["YearDeposit"].ToString());
                }
                if (ds.Tables[0].Rows[0]["YearLimitKM"].ToString() != "")
                {
                    model.YearLimitKM = Convert.ToInt64(ds.Tables[0].Rows[0]["YearLimitKM"].ToString());
                }
                if (ds.Tables[0].Rows[0]["AirportShuttleOneWay"].ToString() != "")
                {
                    model.AirportShuttleOneWay = decimal.Parse(ds.Tables[0].Rows[0]["AirportShuttleOneWay"].ToString());
                }
                if (ds.Tables[0].Rows[0]["AirportShuttleTwoWay"].ToString() != "")
                {
                    model.AirportShuttleTwoWay = decimal.Parse(ds.Tables[0].Rows[0]["AirportShuttleTwoWay"].ToString());
                }
                if (ds.Tables[0].Rows[0]["Chartered3Rent"].ToString() != "")
                {
                    model.Chartered3Rent = decimal.Parse(ds.Tables[0].Rows[0]["Chartered3Rent"].ToString());
                }
                if (ds.Tables[0].Rows[0]["Chartered8Rent"].ToString() != "")
                {
                    model.Chartered8Rent = decimal.Parse(ds.Tables[0].Rows[0]["Chartered8Rent"].ToString());
                }
                if (ds.Tables[0].Rows[0]["OutdatedFee3"].ToString() != "")
                {
                    model.OutdatedFee3 = decimal.Parse(ds.Tables[0].Rows[0]["OutdatedFee3"].ToString());
                }
                if (ds.Tables[0].Rows[0]["OutdatedFee8"].ToString() != "")
                {
                    model.OutdatedFee8 = decimal.Parse(ds.Tables[0].Rows[0]["OutdatedFee8"].ToString());
                }
                if (ds.Tables[0].Rows[0]["LongJourneys1"].ToString() != "")
                {
                    model.LongJourneys1 = decimal.Parse(ds.Tables[0].Rows[0]["LongJourneys1"].ToString());
                }
                if (ds.Tables[0].Rows[0]["LongJourneys2"].ToString() != "")
                {
                    model.LongJourneys2 = decimal.Parse(ds.Tables[0].Rows[0]["LongJourneys2"].ToString());
                }
                if (ds.Tables[0].Rows[0]["LongJourneys3"].ToString() != "")
                {
                    model.LongJourneys3 = decimal.Parse(ds.Tables[0].Rows[0]["LongJourneys3"].ToString());
                }
                if (ds.Tables[0].Rows[0]["ExhaustVolume"].ToString() != "")
                {
                    model.ExhaustVolume = float.Parse(ds.Tables[0].Rows[0]["ExhaustVolume"].ToString());
                }
                if (ds.Tables[0].Rows[0]["CommissionRatio"].ToString() != "")
                {
                    model.CommissionRatio = Convert.ToInt32(ds.Tables[0].Rows[0]["CommissionRatio"].ToString());
                }
                else
                {
                    model.CommissionRatio = 0;
                }

                model.CarImage = ds.Tables[0].Rows[0]["CarImage"] == DBNull.Value ? null : (byte[])ds.Tables[0].Rows[0]["CarImage"];
                return model;
            }
            else
            {
                return null;
            }
        }

        /// <summary>
        /// 获得数据列表
        /// </summary>
        public DataSet GetList(string strWhere)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select  Id,Code,Cartype,Color,FactorCode,MotorCode,dipanCode,StarMax,Max,BuyTime,CareTime,EndCare,Drive,InsureTime,InsureEnd,RoadTime,RoadEnd,Path,State,Seat,BuyPrice,Tax,Shangpaishui,Decorate,Owners,OwnerTel,StarOPen,EndOpen,StarPasTime,EndPass,StarCard,EndCard,Staryunguan,Endyunguan,Starbridge,Endbridge,StarCheshui,EndChenshui,TimeoutPrie,OvertimePrie,DepID,UserId,ShangPaiFei,SendMile,NextMile,Marks,Brand,WarrTime,CarTime,DayRent,CarKind,FactoryOutDate ,CommissionRatio ,ExhaustVolume");
            strSql.Append(" FROM Car ");
            if (strWhere.Trim() != "")
            {
                strSql.Append(" where " + strWhere);
            }
            return SqlHelper.Query(strSql.ToString());
        }

        /// <summary>
        /// 获得数据列表
        /// </summary>
        public DataSet GetAllListForSearchCondistion(string strSql)
        {
            try
            {
                return SqlHelper.Query(strSql);
            }
            catch (Exception )
            {
                return null;
            }
        }


        public List<Model.RemindListInfo> GetRemindListTest()
        {
            List<Model.RemindListInfo> list = new List<Model.RemindListInfo>();
            string strWhere = " 1=1 ";

            Remind remind = new Remind();
            DataSet dsRemind = remind.GetList("");
            int intRoadEnd = 0;
            int intEndbridge = 0;
            int intEndOpen = 0;
            int intEndyunguan = 0;
            int intEndCare = 0;
            int intInsureEnd = 0;
            int intEndChenshui = 0;
            int intNext2KM = 0;

            if (dsRemind != null && dsRemind.Tables[0].Rows.Count > 0)
            {
                foreach (DataRow dr in dsRemind.Tables[0].Rows)
                {
                    if (dr["Name"].ToString().Trim() == "养路费")
                    {
                        intRoadEnd = Convert.ToInt32(dr["HaveTime"].ToString().Trim());
                    }
                    if (dr["Name"].ToString().Trim() == "路桥票")
                    {
                        intEndbridge = Convert.ToInt32(dr["HaveTime"].ToString().Trim());
                    }
                }
            }

            string dtRoadEnd = DateTime.Now.AddDays(intRoadEnd).ToString("yyyy-MM-dd");
            string dtEndbridge = DateTime.Now.AddDays(intEndbridge).ToString("yyyy-MM-dd");
            string dtEndOpen = DateTime.Now.AddDays(intEndOpen).ToString("yyyy-MM-dd");
            string dtEndyunguan = DateTime.Now.AddDays(intEndyunguan).ToString("yyyy-MM-dd");
            string dtEndCare = DateTime.Now.AddDays(intEndCare).ToString("yyyy-MM-dd");
            string dtInsureEnd = DateTime.Now.AddDays(intInsureEnd).ToString("yyyy-MM-dd");
            string dtEndChenshui = DateTime.Now.AddDays(intEndChenshui).ToString("yyyy-MM-dd");

            //RoadEnd 养路费购买截止时间
            strWhere += "or datediff(dd, RoadEnd ,'" + dtRoadEnd + "') >= 0 ";
            //Endbridge 路桥票购买截止时间
            strWhere += "or datediff(dd, Endbridge ,'" + dtRoadEnd + "') >= 0 ";
            //EndOpen 运营办证截止时间
            strWhere += "or datediff(dd, EndOpen ,'" + dtRoadEnd + "') >= 0 ";
            //Endyunguan 运管费截止时间
            strWhere += "or datediff(dd, Endyunguan ,'" + dtEndyunguan + "') >= 0 ";
            //EndCare 年审截止时间
            strWhere += "or datediff(dd, EndCare ,'" + dtEndCare + "') >= 0 ";
            //InsureEnd 保险截止时间
            strWhere += "or datediff(dd, InsureEnd ,'" + dtInsureEnd + "') >= 0 ";
            //EndChenshui 車船稅结束時間
            strWhere += "or datediff(dd, EndChenshui ,'" + dtEndChenshui + "') >= 0 ";
            //EndChenshui 二保里程
            //strWhere += "or Next >'" + intNext2KM.ToString() + "'";

            DataSet ds = GetList(strWhere);
            if (ds != null && ds.Tables[0].Rows.Count > 0)
            {

            }

            return list;
        }

        /// <summary>
        /// 获取提醒列表
        /// </summary>
        /// <returns></returns>
        public List<Model.RemindListInfo> GetRemindList()
        {
            List<Model.RemindListInfo> list = new List<Model.RemindListInfo>();
            string strWhere = " 1=1 ";
            Remind remind = new Remind();
            DataSet dsRemind = remind.GetList("");
            int intHaveTime = 0;
            string dtEnd = "";

            if (dsRemind != null && dsRemind.Tables[0].Rows.Count > 0)
            {
                foreach (DataRow dr in dsRemind.Tables[0].Rows)
                {
                    intHaveTime = Convert.ToInt32(dr["HaveTime"].ToString().Trim());
                    string strColumnName = "";
                    DataSet ds = null;
                    string strRemindName = dr["Name"].ToString().Trim();
                    if (strRemindName != "二保里程")
                    {
                        dtEnd = DateTime.Now.AddDays(intHaveTime).ToString("yyyy-MM-dd");
                    }
                    if (strRemindName == "养路费")
                    {
                        strColumnName = "RoadEnd";
                    }
                    if (strRemindName == "路桥票")
                    {
                        strColumnName = "Endbridge";
                    }
                    if (strRemindName == "运营证")
                    {
                        strColumnName = "EndOpen";
                    }
                    if (strRemindName == "运管费")
                    {
                        strColumnName = "Endyunguan";
                    }
                    if (strRemindName == "年审")
                    {
                        strColumnName = "EndCare";
                    }
                    if (strRemindName == "保险")
                    {
                        strColumnName = "InsureEnd";
                    }
                    if (strRemindName == "车船稅")
                    {
                        strColumnName = "EndChenshui";
                    }
                    if (strRemindName == "二保里程")
                    {
                        strColumnName = "SendMile";
                    }
                    if (strRemindName == "还车提醒")
                    {
                        //获取还车提醒
                        Reserve repair = new Reserve();
                        string strWhereRep = "datediff(dd, EndBooktime ,'" + dtEnd + "') >= 0 and OrderSataus !='true' ";
                        DataSet dsRepair = repair.GetList2(strWhereRep);
                        if (dsRepair != null && dsRepair.Tables[0].Rows.Count > 0)
                        {
                            foreach (DataRow drRep in dsRepair.Tables[0].Rows)
                            {
                                try
                                {
                                    Model.RemindListInfo info = new Model.RemindListInfo();
                                    info.CarID = 0;
                                    info.StartDate = Convert.ToDateTime(drRep["BookTime"].ToString()).ToString("yyyy-MM-dd HH:mm:ss");
                                    info.EndDate = Convert.ToDateTime(drRep["EndBooktime"].ToString()).ToString("yyyy-MM-dd HH:mm:ss");
                                    info.Remarks = drRep["Marks"].ToString();
                                    info.RemindName = strRemindName;
                                    info.HaveTime = intHaveTime;
                                    info.CarCode = drRep["carcode"].ToString();

                                    list.Add(info);
                                }
                                catch (Exception)
                                {
                                }
                            }
                        }
                    }

                    if (strRemindName == "维修提醒")
                    {
                        //获取维修提醒
                        Repair repair = new Repair();
                        string strWhereRep = "datediff(dd, Time ,'" + dtEnd + "') >= 0 and isRemind='true' ";
                        DataSet dsRepair = repair.GetList(strWhereRep);
                        if (dsRepair != null && dsRepair.Tables[0].Rows.Count > 0)
                        {
                            foreach (DataRow drRep in dsRepair.Tables[0].Rows)
                            {
                                try
                                {
                                    Model.RemindListInfo info = new Model.RemindListInfo();
                                    info.CarID = 0;
                                    info.StartDate = Convert.ToDateTime(drRep["Time"].ToString()).ToString("yyyy-MM-dd");
                                    //info.Next2KM = null;
                                    info.Remarks = drRep["Marks"].ToString();
                                    info.RemindName = strRemindName;
                                    info.HaveTime = intHaveTime;
                                    info.CarCode = drRep["CarCode"].ToString();

                                    list.Add(info);
                                }
                                catch (Exception )
                                {
                                }
                            }
                        }
                    }
                    else
                    {
                        ds = GetRemindListByRemindName(strColumnName, dtEnd, strRemindName);
                        AddToRemindList(ds, list, strRemindName, intHaveTime);
                    }
                }
            }


            return list;
        }

        private DataSet GetRemindListByRemindName(string strColumnName, string strDt, string strRemindName)
        {
            string strWhere = "";

            if (strRemindName != "二保里程")
            {
                strWhere += "datediff(dd, " + strColumnName + " ,'" + strDt + "') >= 0 ";
            }
            else
            {
                strWhere += strColumnName + "<= '" + strDt + "'";
            }

            try
            {
                DataSet ds = GetList(strWhere);
                return ds;
            }
            catch (Exception ex)
            {
                return null;
            }
        }

        private bool AddToRemindList(DataSet ds, List<Model.RemindListInfo> list, string strRemindName, int intHaveTime)
        {
            if (ds != null && ds.Tables[0].Rows.Count > 0)
            {
                string strStartTimeColumn = "";
                string strColumnName = "";
                if (strRemindName == "养路费")
                {
                    strStartTimeColumn = "RoadTime";
                    strColumnName = "RoadEnd";
                }
                if (strRemindName == "路桥票")
                {
                    strStartTimeColumn = "Starbridge";
                    strColumnName = "Endbridge";
                }
                if (strRemindName == "运营证")
                {
                    strStartTimeColumn = "StarOPen";
                    strColumnName = "EndOpen";
                }
                if (strRemindName == "运管费")
                {
                    strStartTimeColumn = "Staryunguan";
                    strColumnName = "Endyunguan";
                }
                if (strRemindName == "年审")
                {
                    strStartTimeColumn = "CareTime";
                    strColumnName = "EndCare";
                }
                if (strRemindName == "保险")
                {
                    strStartTimeColumn = "InsureTime";
                    strColumnName = "InsureEnd";
                }
                if (strRemindName == "车船稅")
                {
                    strStartTimeColumn = "StarCheshui";
                    strColumnName = "EndChenshui";
                }
                if (strRemindName == "还车提醒")
                {
                    strStartTimeColumn = "InsureTime";
                    strColumnName = "InsureEnd";
                }
                //if (strRemindName == "二保里程")
                //{
                //    strColumnName = "SendMile";
                //}
                foreach (DataRow dr in ds.Tables[0].Rows)
                {
                    try
                    {
                        Model.RemindListInfo info = new Model.RemindListInfo();
                        info.CarID = Convert.ToInt32(dr["Id"].ToString());
                        if (strRemindName != "二保里程")
                        {
                            info.EndDate = Convert.ToDateTime(dr[strColumnName].ToString()).ToString("yyyy-MM-dd");
                            info.StartDate = Convert.ToDateTime(dr[strStartTimeColumn].ToString()).ToString("yyyy-MM-dd");
                        }
                        info.Next2KM = Convert.ToInt32(dr["NextMile"].ToString());
                        info.Remarks = dr["Marks"].ToString();
                        info.RemindName = strRemindName;
                        info.HaveTime = intHaveTime;
                        info.CarCode = dr["Code"].ToString();

                        list.Add(info);
                    }
                    catch (Exception ex)
                    {
                    }
                }
            }

            return true;
        }

        public bool UpdateCarStatus(int carID, DateTime dtCarTime, bool status)
        {
            SqlParameter[] parameters = {
					new SqlParameter("@Id", SqlDbType.Int,4),
                    new SqlParameter("@CarTime", SqlDbType.DateTime),
					new SqlParameter("@State", SqlDbType.Bit,1)};
            parameters[0].Value = carID;
            parameters[1].Value = dtCarTime;
            parameters[2].Value = status;

            int intResult = SqlHelper.ExecuteNonQuery(CommandType.StoredProcedure, "ArticleCar_UpdateStatus", parameters);
            if (intResult > 0)
                return true;
            else
                return false;
        }
    }

}
